#include "QxTableModel.hpp"

QxTableModel::QxTableModel( QObject* parent ) : QAbstractTableModel( parent )
{
  m_buffer.clear();
}

QxTableModel::~QxTableModel()
{
}

const QVector<float>& QxTableModel::buffer() const
{
  return m_buffer;
}

void QxTableModel::setBuffer( const QVector<float>& buffer )
{
  if( m_buffer != buffer ) {
    m_buffer = buffer;
    reset();
  }
}

int QxTableModel::rowCount( const QModelIndex& ) const
{
  return m_buffer.count();
}

int QxTableModel::columnCount( const QModelIndex& ) const
{
  return 1;
}

QVariant QxTableModel::data( const QModelIndex& index, int role ) const
{
  if( !index.isValid() || role != Qt::DisplayRole || m_buffer.isEmpty() ) {
    return QVariant();
  }

  return m_buffer.at( index.row() );
}

QVariant QxTableModel::headerData( int section, Qt::Orientation orientation, int role/*=Qt::DisplayRole */ ) const
{
  if( !section && orientation==Qt::Horizontal && role==Qt::DisplayRole ) {
    return QVariant( tr( "Data" ) );
  }

  return QAbstractTableModel::headerData( section, orientation, role );
}
